<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script type="text/javascript" data-order="1" data-src="js/libs/jquery.js"></script>
        <script type="text/javascript" data-order="1" data-src="js/libs/spine.js"></script>
        <script type="text/javascript" data-order="2" data-src="js/app.js"></script>
        <script type="text/javascript" id="master">
            var scripts = document.getElementsByTagName('script');
            var d = document || window.document;
            var head = d.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'head')[0];
            var master = d.getElementById('master');
            var toLoad = [];
            var toRemove = [];
            // Loop Through all Script Tags
            // Determine Group and Src
            // Determine Load Orders and Create Arrays
            // Loop Arrays and insert Script Tags
            // Remove All old script tags
            for(var i = 0; i < scripts.length; i++) {
                var script = scripts[i];
                if(script.getAttribute('src') == undefined && script.getAttribute('id') != 'master') {
                    var order = script.getAttribute('data-order');
                    if(toLoad[order] == undefined) {
                        toLoad[order] = [];
                    }
                    var lScript = d.createElement('SCRIPT');
                    var src = script.getAttribute('data-src');
                    lScript.src = src;
                    lScript.type = 'text/javascript';
                    lScript.text = 'test';
//                    master.parentNode.insertBefore(lScript, master);
//                    master.parentNode.removeChild(script);
                    if(order != undefined)
                        toLoad[order].push(lScript);
                    toRemove.push(script);
                }
            }
            for(var i in toLoad) {
                var order = toLoad[i];
                for(var j = 1; j < order.length; j++) {
                    var script = order[j];
//                    master.parentNode.insertBefore(lScript, master);
                }
            }
            console.log(toLoad);
            console.log(toRemove);
        </script>
        
    </head>
    <body>
        <div>TODO write content</div>
    </body>
</html>
